package com.my.blog.website.controller.user;

import com.my.blog.website.constant.WebConst;
import com.my.blog.website.controller.BaseController;
import com.my.blog.website.service.IContentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;


/**
 * @author geng
 * @title: SearchShowController
 * @projectName my-blog
 * @description: TODO
 * @date 2020/1/14 -- 11:00
 */
@Controller
public class SearchShowController extends BaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(IndexController.class);

    @Autowired
    private IContentService contentService;


    /**
     * 搜索页
     *
     * @param
     * @return
     */
    @PostMapping("/search")
    public String postSearch(@PageableDefault(size = WebConst.MAX_POSTS) Pageable pageable, @RequestParam String query, Model model) {
        //LOGGER.info("每页条数为{}",pageable.getPageSize());
        model.addAttribute("page", contentService.getArticles(query, pageable.getPageNumber(), pageable.getPageSize()));
        model.addAttribute("query", query);
        return "search";
    }

}
